<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$return=array();
$return['isopenvoice']=$this->session('isopenvoice')?1:0;
if($_RQ['op']=='main'){
    $worker = pdo_get('jy_shifu_member',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1));
    if(empty($worker)){
        exi('您不是师傅！','error','/apply/');
    }
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	$cashdays=$this->setting['cash_day']?:1;
	$cashtime = mktime(0,0,0,date('m'),date('d')-$cashdays,date('Y'));
	$return['get_money']=pdo_getsum('jy_shifu_orderlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']),'get_money');
	$return['lastget_money']=pdo_getsum('jy_shifu_orderlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>0),'get_money');
	$return['yesget_money']=pdo_getsum('jy_shifu_orderlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>0,'createtime <'=>$cashtime),'get_money');
	
	$worker['today_num']=pdo_count('jy_shifu_shoulog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>2,'createtime >'=>$daytime));
	$worker['today_money']=pdo_getsum('jy_shifu_orderlog',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>0,'createtime >'=>$cashtime),'get_money');
	$worker['all_num']=$return['get_money'];
	$worker['all_money']=$return['get_money'];
	$worker['leveltitle']=pdo_getcolumn('jy_shifu_group',array('id'=>$worker['group_id'],'uniacid'=>$_SESSION['uniacid']),'title');
	$worker['leveltitle']=$worker['leveltitle']?:'默认等级';
	set_html('title','师傅中心');
	if($_SESSION['wxapp_id']){
		$tmpid=cfc('wxapp_api')->get_tpl_template_id('17468',[1,2,3,7],'orderget','新师傅任务通知','jy_shifu');
		if($tmpid){
			$tmplIds[]=$tmpid;
		}
		$return['tmplIds']=$tmplIds;
	}
	$return['worker']=$worker;
	exi($return);
	
}
if($_RQ['op']=='set'){
	if($_RQ['postdata']){
		$postdata=get_postdata();	
		$data=array(
				'headimg'=>$postdata['headimg'],
				'title'=>$postdata['title'],
				'address'=>$postdata['address'],
				'mobile'=>$postdata['mobile'],
		);
		$worker_id=pdo_getcolumn('jy_shifu_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),'id');		
		if($worker_id){
			pdo_update('jy_shifu_member',$data,array('id'=>$worker_id));
			exi('修改成功','','main');		 
		}
	}
	$worker=pdo_get('jy_shifu_member',array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	$return['worker']=$worker;
	exi($return);
}
if($_RQ['op']=='setonline'){
	$post=get_postdata();
	$id=$post['id'];
	$online=$post['online'];
	pdo_update('jy_shifu_member',array('online'=>$online),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	if($online==0){
		exi('成功离线！');	
	}elseif($online==1){
		exi('成功上线！');	
	}elseif($online==2){
		exi('成功忙碌！');	
	}	 
}
if($_RQ['op']=='getworkers'){
    if($_RQ['lat'] || $_RQ['lng']){
        $lat_lng=array('lat'=>$_RQ['lat'],'lng'=>$_RQ['lng']);
        $this->session('lat_lng',$lat_lng);
    }
    $lat_lng=$this->session('lat_lng')?:array('lat'=>'31.235929','lng'=>'121.480539');
    $list=$this->model('member')->getlist($lat_lng,$_RQ['maxjuli'],$_RQ['limit'],$_RQ['page']);
    $markers=array();
    if(count($list)){
        $title='附近有'.count($list).'位师傅';
    }else{
        $title='附近暂时没有师傅';
    }
    $this->setting['nv_icon']=$this->setting['nv_icon']?tomedia($this->setting['nv_icon']):tomedia('../addons/jy_shifu/resource/images/nv_icon.png');
    $nomarkers=array(
        'nowjuli'=>0,
        'latitude'=>$lat_lng['lat'],
        'longitude'=>$lat_lng['lng'],
        'lat_lng'=>$lat_lng,
        'title'=>$title,
        'iconPath'=> $this->setting['nv_icon'],
        'width'=>36,
        'height'=>36,
        'callout'=>array(
            'content'=>$title,
            'borderRadius'=>5,
            'bgColor'=>'#cdab6a',
            'color'=>'#fff',
            'textAlign'=>'center',
            'padding'=>5,
            'anchorY'=>0,
            'display'=>'ALWAYS',
            'borderColor'=>'#cdab6a',
        ),
    );
    $markers[]=$nomarkers;
    $this->setting['nv_icon']=$this->setting['nv_icon']?tomedia($this->setting['nv_icon']):tomedia('../addons/jy_shifu/resource/images/nv_icon.png');
    foreach($list as $k=>&$item){
        $name=cfc('tools')->substr($item['title'],0,1);
        $name .='师傅';
        $markers[]=array(
            'nowjuli'=>$item['nowjuli'],
            'latitude'=>$item['lat_lng']['lat'],
            'longitude'=>$item['lat_lng']['lng'],
            'lat_lng'=>$item['lat_lng'],
            'title'=>$name,
            'iconPath'=>$this->setting['nv_icon'],
            'width'=>26,
            'height'=>26,
            'callout'=>array(
                'content'=>$name,
                'borderRadius'=>5,
                'bgColor'=>'#cdab6a',
                'color'=>'#fff',
                'textAlign'=>'center',
                'padding'=>5,
                'anchorY'=>0,
                'borderColor'=>'#cdab6a',
            ),
        );
    }

    $return['list']=$markers;
    exi($return);
}
if($_RQ['op']=='getnew'){
	$params=array(
		'status'=>array(1,15),
		'sendtype'=>1,
		'send_status'=>array(0,12),
		'uniacid'=>$_SESSION['uniacid'],
	);
	$order=pdo_get('jy_weishop_order',$params);
	if($order['id']){
		exi($order);
	}else{
		exi('none');
	}
}
if($_RQ['op']=='setopenvoice'){
	$isopenvoice=$_RQ['isopenvoice'];
	$isopenvoice=$isopenvoice?1:0;
	pdo_update('jy_shifu_member',array('online'=>$isopenvoice),array('mid'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']));
	exi($return);
}
?>